//
//  TheCustomButton.m
//  newTestGit
//
//  Created by fangjs on 16/3/10.
//  Copyright © 2016年 Hongshi. All rights reserved.
//

#import "TheCustomButton.h"
#define kImageHeightProportion 0.8

@implementation TheCustomButton

- (void) awakeFromNib {
    [self setUpdateSubControls];
}

- (instancetype) initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpdateSubControls];
    }
    return self;
}

#pragma mark -- 取消高亮显示
- (void) setHighlighted:(BOOL)highlighted {
    
}

- (void) setUpdateSubControls {
    self.imageView.contentMode = UIViewContentModeCenter;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}

#pragma mark - 更改 button 内部的 image 和 label 的 frame
-(void)layoutSubviews {
    [super layoutSubviews];
    //UIImageView
    CGFloat imageX = 0;
    CGFloat imageY = 0;
    CGFloat imageW = self.bounds.size.width;
    CGFloat imageH = self.bounds.size.height * kImageHeightProportion;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
    
    //Title
    CGFloat labelY = imageH;
    CGFloat labelH = self.bounds.size.height - labelY;
    self.titleLabel.frame = CGRectMake(imageX, labelY, imageW, labelH);
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end



























